package com.cmcc.cmii.smsmail.utils;

import com.cmcc.cmii.smsmail.entity.MailBaseInfo;
import com.cmcc.cmii.smsmail.model.BaseMail;
import com.cmcc.cmii.smsmail.model.v1.SimpleMail;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

/**
 * @author Thanks
 */
public class MailUtil {

    /**
     * 获取 Sender 多实例发送
     * @return
     */
    public static JavaMailSenderImpl createMailSender(String host,Integer port,String username,String password,String protocol){
        JavaMailSenderImpl sender = new JavaMailSenderImpl();
        sender.setHost(host);
        sender.setPort(port);
        sender.setUsername(username);
        sender.setPassword(password);
        sender.setDefaultEncoding("UTF-8");
        sender.setProtocol(protocol);
        Properties p = new Properties();
        p.setProperty("mail.smtp.timeout","1000");
        p.setProperty("mail.smtp.auth","true");
        sender.setJavaMailProperties(p);
        return sender;
    }

    /**
     *获取邮箱对象
     * @param mailBaseInfo
     * @param baseMail
     * @return
     */
    public static JavaMailSenderImpl createMailSender(MailBaseInfo mailBaseInfo, BaseMail baseMail){

        JavaMailSenderImpl sender = new JavaMailSenderImpl();
        sender.setHost(mailBaseInfo.getMailHost());
        sender.setPort(mailBaseInfo.getMailPort());
        sender.setUsername(baseMail.getUsername());
        sender.setPassword(baseMail.getPassword());
        sender.setDefaultEncoding("UTF-8");
        sender.setProtocol(mailBaseInfo.getMailProtocol());
        Properties p = new Properties();
        p.setProperty("mail.smtp.timeout","1000");
        p.setProperty("mail.smtp.auth","true");
        sender.setJavaMailProperties(p);
        return sender;
    }





    public static void main(String[] args) throws MessagingException {
        /*SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("692899857@qq.com");
        message.setTo("692899857@qq.com","692899857@qq.com");
        message.setSubject("测试");
        message.setText("测试");*/
      /*  JavaMailSenderImpl mailSender = createMailSender("smtp.qq.com", 587, "692899857@qq.com", "xxizxxxejzmgbdgc", "smtp");
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);*/

      Integer a = 1;
      Integer b = 2;
        System.out.println(a.equals(b));

    }



}
